from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


chrome_options = webdriver.ChromeOptions()

prefs = {
    'profile.default_content_settings.popups': 0,
    'download.default_directory': '/Users/palm/InvestData/',
    "profile.managed_default_content_settings.images": 2
}
# chrome_options.add_argument('--headless')
chrome_options.add_experimental_option('prefs', prefs)

browser = webdriver.Chrome(executable_path="../utils/chromedriver", options=chrome_options)

browser.get("https://cn.investing.com/")
browser.find_element_by_css_selector('a.login').click()

login_browser = browser.find_element_by_id("loginPopup")
login_browser.find_element_by_id("loginFormUser_email").send_keys("palmzhang19@gmail.com")
login_browser.find_element_by_id("loginForm_password").send_keys("xiaodai820828_")
time.sleep(1)
login_browser.find_element_by_css_selector('a.newButton').click()
# cookie = [item['name'] + '=' + item['value'] for item in browser.get_cookies()]
# cookies = ''
# for value in cookie:
#     cookies += value + ';'
#
# print(cookies)
